package com.bnzj.cloud.business.core.persistence.repository;

import com.bnzj.cloud.business.core.persistence.entity.SysRoleResource;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysResourceRoleRepository extends BaseRepository<SysRoleResource, Long> {

    @Query(value = "select * from bnz_sys_role_resource where role_id=?1", nativeQuery = true)
    List<SysRoleResource> findResourceRoleBy(Long id);

    @Modifying
    @Query(value = "delete from bnz_sys_role_resource where role_id=?1", nativeQuery = true)
    void deleteByRoleId(Long roleId);

    @Query(value = "SELECT r.resource_id FROM bnz_sys_role_resource r WHERE r.role_id =?1", nativeQuery = true)
    List<Long> findResourceIdsByRoleId(Long roleId);

    @Modifying
    @Query(value = "delete from bnz_sys_role_resource where resource_id=?1", nativeQuery = true)
    Object deleteByResourceId(Long id);

}
